home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 September / macformat-041.iso / mac / Shareware City / Graphics / MacSPD / Sources / def.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-13  |  6.6 KB  |  236 lines  |  [TEXT/MMCC]

  1. /*
  2.  * def.h contains some useful definitions for "C" programs.
  3.  *
  4.  * Author:  Eric Haines, 3D/Eye, Inc.
  5.  *
  6.  * Modified: 1 October 1992
  7.  *           Alexander R. Enzmann
  8.  * Modified: 14 December 1992  - Better Mac (MPW) compatibility
  9.  *           Eduard [esp] Schwan
  10.  * Modified: 2 August 1993  - More ANSI C & Mac compatibility fixes
  11.  *           Eduard [esp] Schwan
  12.  * Modified: 4 September 1993  - Added one more generator (LATTICE)
  13.  *           Antonio [acc] Costa
  14.  * Modified: 6 September 1993  - Changed LATTICE to GENERIC, other renames
  15.  *           Eric Haines
  16.  * Modified: 16 September 1993  - Added SPD_LATTICE & SPD_SHELLS defines
  17.  *           Eduard [esp] Schwan
  18.  * Modified: 27 July 1994  - Added __MWERKS__ define for Metrowerks compiler
  19.  *           Eduard [esp] Schwan
  20.  * Modified: 2 November 1994  - Added COMB_COORD
  21.  *           Alexander R. Enzmann
  22.  *
  23.  */
  24.  
  25. #ifndef DEF_H
  26. #define DEF_H
  27.  
  28. #if __cplusplus
  29. extern "C" {
  30. #endif
  31.  
  32. /*
  33.  * Each data base/program is defined here.  These are used as
  34.  * parameters to the PLATFORM_INIT() macro, in case the programs
  35.  * need to behave differently based on the type of db run.  For
  36.  * example, the Macintosh version must prompt the user for input
  37.  * parameters instead of getting them on the command line.  This
  38.  * allows the Mac to use a different dialog box for each program.
  39.  */
  40.  
  41. #define SPD_MIN                1
  42. #define SPD_BALLS              1
  43. #define SPD_GEARS              2
  44. #define SPD_MOUNT              3
  45. #define SPD_RINGS              4
  46. #define SPD_TEAPOT             5
  47. #define SPD_TETRA              6
  48. #define SPD_TREE               7
  49. #define SPD_READDXF            8
  50. #define SPD_LATTICE            9
  51. #define SPD_SHELLS            10
  52. #define SPD_READNFF           11
  53. #define SPD_READOBJ           12
  54. #define SPD_JACKS             13
  55. #define SPD_SOMBRERO          14
  56. #define SPD_GENERIC           15
  57. #define SPD_MAX               SPD_GENERIC
  58.  
  59.  
  60. /* ---- Macintosh-specific definitions here ---- */
  61.  
  62. #if defined(applec) || defined(THINK_C) || defined(__MWERKS__)
  63. #define PARAMS(x)  x
  64.  
  65. /* If OUTPUT_TO_FILE is defined, output goes to new text file, not to stdout */
  66. #define OUTPUT_TO_FILE            true
  67.  
  68. #define PLATFORM_INIT(spdType)    MacInit(&argc, &argv, spdType)
  69. #define PLATFORM_MULTITASK()      MacMultiTask()
  70. #define PLATFORM_SHUTDOWN()       MacShutDown()
  71.  
  72. #define EPSILON  1.0e-15
  73. #define EPSILON2 1.0e-7
  74.  
  75. #if defined(__MWERKS__)
  76. #undef NULL
  77. #define NULL ((void*)0L)
  78. #endif
  79.  
  80. #if defined(applec)
  81. #include <math.h>
  82. #define PI      pi()
  83. #endif /* applec */
  84.  
  85.  
  86. /*
  87.  * declared in drv_mac.c
  88.  */
  89. extern void          MacInit(int *argcp, char ***argvp, int spdType);
  90. extern void          MacMultiTask(void);
  91. extern void          MacShutDown(void);
  92. /* extern short      macParmOutFormat; */
  93. /* extern short      macParmSize; */
  94. /* extern short      macParm2; */
  95. #endif /* applec || THINK_C */
  96.  
  97.  
  98.  
  99. /* Use "PARAMS(x) ()" above if your compiler can't handle function prototyping,
  100.  * "PARAMS(x) x" if it can use ANSI headers.
  101.  */
  102. #ifndef PARAMS
  103.  
  104. /* check if ANSI headers should be available */
  105. #if __STDC__ || defined(__cplusplus)
  106. /* yes, ANSI headers */
  107. #define PARAMS(x)  x
  108. #else
  109. /* no, no ANSI headers */
  110. #define PARAMS(x) ()
  111. #endif
  112.  
  113. #endif
  114.  
  115.  
  116. /*
  117.  * PLATFORM_xxx macros are used to allow different OS platforms
  118.  * hooks to do their own initialization, periodic tasks, and
  119.  * shutdown cleanup, if needed. [esp]
  120.  */
  121.  
  122. #ifndef PLATFORM_INIT
  123. #define PLATFORM_INIT(spdType)
  124. #endif /* PLATFORM_INIT */
  125.  
  126. #ifndef PLATFORM_MULTITASK
  127. #define PLATFORM_MULTITASK()
  128. #endif /* PLATFORM_MULTITASK */
  129.  
  130. #ifndef PLATFORM_SHUTDOWN
  131. #define PLATFORM_SHUTDOWN()
  132. #endif /* PLATFORM_SHUTDOWN */
  133.  
  134.  
  135. /* exit codes - define as you wish */
  136. #define EXIT_SUCCESS    0
  137. #define EXIT_FAIL       1
  138.  
  139. #ifndef EPSILON
  140. #define EPSILON 1.0e-8
  141. #endif
  142.  
  143. #ifndef EPSILON2
  144. #define EPSILON2 1.0e-6
  145. #endif
  146.  
  147. #ifndef FALSE
  148. #define FALSE 0
  149. #endif
  150.  
  151. #ifndef NULL
  152. #define NULL 0
  153. #endif
  154.  
  155. #ifndef TRUE
  156. #define TRUE 1
  157. #endif
  158.  
  159. #ifndef PI
  160. #define PI 3.141592653589793
  161. #endif
  162.  
  163. typedef double MATRIX[4][4] ;  /* row major form */
  164.  
  165. typedef double  COORD3[3] ;
  166. typedef double  COORD4[4] ;
  167.  
  168. /* COORD3/COORD4 indeces */
  169. #define        X       0
  170. #define        Y       1
  171. #define        Z       2
  172. #define        W       3
  173.  
  174. /* COORD3 (color) indeces */
  175. #define    R_COLOR     0
  176. #define    G_COLOR     1
  177. #define    B_COLOR     2
  178.  
  179. #define POW(A,B)     ( (A) == 0.0 ? 0.0 : ( (B) == 0.0 ? 1.0 : pow(A, B) ) )
  180. #define SGN(A)       ( (A) < 0.0 ? -1.0 : ( (A) > 0.0 ? 1.0 : 0.0) )
  181. #define ABSOLUTE(A)            ( (A) < 0 ? -(A) : (A) )
  182. #define FRACTION(A)             ( (A) - (int)(A) )
  183. #define       IS_VAL_ALMOST_ZERO(A,E) ( ABSOLUTE(A) <= (E) )
  184. #define   MAX(A,B)                ( (A) > (B) ? (A) : (B) )
  185. #define        MIN(A,B)                ( (A) < (B) ? (A) : (B) )
  186. #define SQR(A)                 ( (A) * (A) )
  187.  
  188. #define ADD2_COORD3(r,a)   { (r)[X] += (a)[X]; (r)[Y] += (a)[Y];\
  189.                 (r)[Z] += (a)[Z]; }
  190. #define ADD3_COORD3(r,a,b) { (r)[X] = (a)[X] + (b)[X];\
  191.                   (r)[Y] = (a)[Y] + (b)[Y];\
  192.                   (r)[Z] = (a)[Z] + (b)[Z]; }
  193. #define COPY_COORD3(r,a)   { (r)[X] = (a)[X];\
  194.                    (r)[Y] = (a)[Y];\
  195.                    (r)[Z] = (a)[Z];}
  196. #define COPY_COORD4(r,a)     { (r)[X] = (a)[X];\
  197.                    (r)[Y] = (a)[Y];\
  198.                    (r)[Z] = (a)[Z];\
  199.                    (r)[W] = (a)[W]; }
  200. #define CROSS(r,a,b)                { (r)[X] = (a)[Y] * (b)[Z] - (a)[Z] * (b)[Y];\
  201.                 (r)[Y] = (a)[Z] * (b)[X] - (a)[X] * (b)[Z];\
  202.                 (r)[Z] = (a)[X] * (b)[Y] - (a)[Y] * (b)[X]; }
  203. #define DOT_PRODUCT(a,b) ( (a)[X] * (b)[X] +\
  204.                   (a)[Y] * (b)[Y] +\
  205.                   (a)[Z] * (b)[Z] )
  206. #define DOT4(a,b)            ( (a)[X] * (b)[X] +\
  207.                   (a)[Y] * (b)[Y] +\
  208.                   (a)[Z] * (b)[Z] +\
  209.                   (a)[W] * (b)[W] )
  210. #define IS_COORD3_ALMOST_ZERO(a,E)   (\
  211.                    IS_VAL_ALMOST_ZERO( (a)[X], (E) )\
  212.                && IS_VAL_ALMOST_ZERO( (a)[Y], (E) )\
  213.                && IS_VAL_ALMOST_ZERO( (a)[Z], (E) ) )
  214. #define SET_COORD3(r,A,B,C)     { (r)[X] = (A); (r)[Y] = (B); (r)[Z] = (C); }
  215. #define SET_COORD4(r,A,B,C,D)      { (r)[X] = (A); (r)[Y] = (B); (r)[Z] = (C);\
  216.                   (r)[W] = (D); }
  217. #define SUB2_COORD3(r,a)       { (r)[X] -= (a)[X]; (r)[Y] -= (a)[Y];\
  218.                 (r)[Z] -= (a)[Z]; }
  219. #define SUB3_COORD3(r,a,b) { (r)[X] = (a)[X] - (b)[X];\
  220.                   (r)[Y] = (a)[Y] - (b)[Y];\
  221.                   (r)[Z] = (a)[Z] - (b)[Z]; }
  222. #define LERP_COORD(r, a, b, u) { (r)[X] = (a)[X] + (u) * ((b)[X] - (a)[X]);\
  223.                 (r)[Y] = (a)[Y] + (u) * ((b)[Y] - (a)[Y]);\
  224.                  (r)[Z] = (a)[Z] + (u) * ((b)[Z] - (a)[Z]); }
  225. #define COMB_COORD(r, a, b, u, v) { (r)[X] = (a)[X] * (u) + (b)[X] * (v);\
  226.                     (r)[Y] = (a)[Y] * (u) + (b)[X] * (v);\
  227.                     (r)[Z] = (a)[Z] * (u) + (b)[X] * (v); }
  228. #define RAD2DEG(x) (180.0*(x)/3.1415926535897932384626)
  229.  
  230. #if __cplusplus
  231. }
  232. #endif
  233.  
  234.  
  235. #endif /* DEF_H */
  236.